<template>
    <div>
        <myMain/>

        <div class="aui-logon-con">
            <div class="b-line">
                <input type="text" v-model="username" placeholder="手机号/邮箱/用户名">
            </div>
            <div class="b-line">
                <input type="password" v-model="password" placeholder="密码">
            </div>
            <div class="aui-login-l">
                <a href="javascript:;" @click="login">登录</a>
            </div>
            <div class="aui-login-wen">
                <div class="aui-login-wen-a"><router-link :to="{name:'reg'}"> 注册</router-link></div>
                <div><a href="modify.html">忘记密码?</a> </div>
            </div>
            <div class="aui-login-san">
                <div class="aui-login-qq"><a href="#"></a></div>
                <div class="aui-login-wb"><a href="#"></a></div>
                <div class="aui-login-wx"><a href="#"></a></div>
            </div>
        </div>
    </div>
</template>
<script>
import myMain from '@/components/myMain'
export default {
    name:'login',
    data(){
        return{
            username:'',
            password:''
        }
    },
    components: {
        myMain
    },
    methods: {
        login(){
            let data ={
                username:this.username,
                password:this.password
            }
            let flag = false;
            if(this.username!=''&&this.password!=''){
                let userList = localStorage.getItem('userList')
                let userL = JSON.parse(userList)
                if(userL!=null){
                    for(let i=0;i<userL.length;i++){
                        if(userL[i].username==data.username){
                            if(userL[i].password==data.password){
                                flag = true
                            }
                        }
                    }
                }else{
                    userL = []
                }
                if(flag){
                    if(confirm('登录成功,是否跳转到个人中心？')){
                        sessionStorage.setItem('username',data.username)
                        sessionStorage.setItem('isLogin',true)
                        this.$router.replace('me')
                    }
                }else{
                    alert('用户名或密码不正确，请重新输入')
                }
            }else{
                alert('请输入用户名或密码')
            }
        }
    }
}

</script>
<style scoped src="../../static/css/ui.css">

</style>


